//
//  customViewToolBar.m
//  BeautyPicture
//
//  Created by 沈振邦 on 15/10/17.
//  Copyright (c) 2015年 szb. All rights reserved.
//

#import "customViewToolBar.h"

@implementation customViewToolBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //self.backgroundColor = BPGlobaBGColor;
       
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 70)];
        bgView.alpha = 0;
        bgView.backgroundColor = BPGlobaBGColor;
        [self addSubview:bgView];
        
        [self addPicMakeButton:@"xuanzhuan" FrameIndex:0];
        [self addPicMakeButton:@"huantu" FrameIndex:1];
        [self addPicMakeButton:@"jingxiang" FrameIndex:2];
        [self addPicMakeButton:@"fangda" FrameIndex:3];
        [self addPicMakeButton:@"suoxiao" FrameIndex:4];
    }
    return self;
}

- (void)addPicMakeButton:(NSString *)btnImage FrameIndex:(NSInteger)framIndex
{
    
    UIButton *picChangeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    picChangeBtn.tag = 10000+framIndex;
    [picChangeBtn setImage:[UIImage imageNamed:btnImage] forState:UIControlStateNormal];
    picChangeBtn.frame = CGRectMake(63 * framIndex + 7.0, 8, 55, 54);
    [picChangeBtn addTarget:self action:@selector(changeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    picChangeBtn.backgroundColor = BPBlockColor;
    // 透明度 不能写, 原因:写了透明度之后 点击的 时候,button的背景颜色 也会随着改变.
//    picChangeBtn.alpha = 0.9;
    [self addSubview:picChangeBtn];
    
}

- (void)changeBtnClick:(UIButton *)Button
{
    if (Button.tag == 10000) {
        [self addPicMakeButton:@"huantu" FrameIndex:1];
        [self addPicMakeButton:@"jingxiang" FrameIndex:2];
        [self addPicMakeButton:@"fangda" FrameIndex:3];
        [self addPicMakeButton:@"suoxiao" FrameIndex:4];
        [self addPicMakeButton:@"xuanzhuan-over" FrameIndex:0];
        [self xuanzhuan];
    }else if (Button.tag == 10001){
        [self addPicMakeButton:@"xuanzhuan" FrameIndex:0];
        [self addPicMakeButton:@"jingxiang" FrameIndex:2];
        [self addPicMakeButton:@"fangda" FrameIndex:3];
        [self addPicMakeButton:@"suoxiao" FrameIndex:4];
        [self addPicMakeButton:@"huantu-over" FrameIndex:1];
        [self albumChoose];
    }else if (Button.tag == 10002){
        [self addPicMakeButton:@"xuanzhuan" FrameIndex:0];
        [self addPicMakeButton:@"huantu" FrameIndex:1];
        [self addPicMakeButton:@"fangda" FrameIndex:3];
        [self addPicMakeButton:@"suoxiao" FrameIndex:4];
        [self addPicMakeButton:@"jingxiang-over" FrameIndex:2];
        [self mirrorImage];
    }else if (Button.tag == 10003){
        [self addPicMakeButton:@"xuanzhuan" FrameIndex:0];
        [self addPicMakeButton:@"huantu" FrameIndex:1];
        [self addPicMakeButton:@"jingxiang" FrameIndex:2];
        [self addPicMakeButton:@"suoxiao" FrameIndex:4];
        [self addPicMakeButton:@"fangda-over" FrameIndex:3];
        [self addImageSize];
    }else if (Button.tag == 10004){
        [self addPicMakeButton:@"xuanzhuan" FrameIndex:0];
        [self addPicMakeButton:@"huantu" FrameIndex:1];
        [self addPicMakeButton:@"jingxiang" FrameIndex:2];
        [self addPicMakeButton:@"fangda" FrameIndex:3];
        [self addPicMakeButton:@"suoxiao-over" FrameIndex:4];
        [self reduceImageSize];
    }
}

- (void)xuanzhuan
{
    if (self.delegate !=nil && [self.delegate respondsToSelector:@selector(rotaImage)]) {
        [self.delegate rotaImage];
    }
}

- (void)albumChoose
{
    if (self.delegate !=nil && [self.delegate respondsToSelector:@selector(albumChoose)]) {
        [self.delegate albumChoose];
    }
}

- (void)mirrorImage
{
    if (self.delegate !=nil && [self.delegate respondsToSelector:@selector(mirrorImage)]) {
        [self.delegate mirrorImage];
    }
}

- (void)addImageSize
{
    if (self.delegate !=nil && [self.delegate respondsToSelector:@selector(addImageSize)]) {
        [self.delegate addImageSize];
    }
}

- (void)reduceImageSize
{
    if (self.delegate !=nil && [self.delegate respondsToSelector:@selector(reduceImageSize)]) {
        [self.delegate reduceImageSize];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
